<template>
    <div>
        <h2>科室信息更改</h2>
        <table class="table">
            <tbody>
                <tr>
                    <td>科室名称</td>
                    <td><input type="text" v-model="data.name" name="" id=""></td>
                </tr>
                <tr>
                    <td>科室人数</td>
                    <td><input v-model="data.pnum" type="text" name="" id=""></td>
                </tr>
                <tr>
                    <td>科室介绍</td>
                    <td><textarea name="" id="" v-model="data.jieshao"></textarea></td>
                </tr>
                <tr>
                    <td>创建时间</td>
                    <td>
                        <input v-model="data.createdate" type="date" name="" id="">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="修改" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';

const route= useRoute();
const router=useRouter();
onMounted(()=>{
    show();
})
const show=()=>{
    var id=route.query.id;
    axios.get('https://localhost:7260/api/KeShi/GetKeshi',{params:{id:id}}).then(res=>{
        data.value=res.data;
        data.value.createdate=data.value.createdate.substring(0,10);
    })
}
const data=ref({
  "id": 0,
  "name": "",
  "pnum": 0,
  "jieshao": "",
  "createdate": "",
  "del": false,
  "people": "string",
  "adddate": "2025-02-18T07:42:37.659Z"
})

const add=()=>{
    axios.put('https://localhost:7260/api/KeShi/UpdateKeshi',data.value).then(res=>{
        if(res.data>0){
            alert('修改成功');
            router.push('/showks');
        }
        else{
            alert('失败');
        }
    })
}
</script>

<style scoped>

</style>